﻿import { Router } from "express";
const r = Router();

const sites = [
  { id: "hosp1", name: "市人民医院", center: [120.1551, 30.2741], zoom: 16 },
  { id: "hosp2", name: "市中医院", center: [120.1700, 30.2500], zoom: 16 },
  { id: "hosp3", name: "第一医院", center: [120.1900, 30.2800], zoom: 16 },
  { id: "hosp4", name: "第三人民医院", center: [120.2000, 30.2600], zoom: 16 },
];

r.get("/sites", (req, res) => {
  const q = (req.query.q as string || "").toLowerCase();
  const offset = parseInt((req.query.offset as string) || "0", 10);
  const limit = Math.max(1, Math.min(100, parseInt((req.query.limit as string) || "20", 10)));

  const filtered = q
    ? sites.filter((s) => s.name.toLowerCase().includes(q) || s.id.toLowerCase().includes(q))
    : sites;

  const paged = filtered.slice(offset, offset + limit);
  res.json({ items: paged, total: filtered.length, offset, limit });
});

r.get("/levels", (req, res) => res.json({ site: req.query.site || "HOSP1", levels: ["L1","L2"] }));
r.get("/pois", (_req, res) => res.json({ items: [] }));
r.get("/legend", (_req, res) => res.json({ legend: { density: [0,5] }}));
export default r;
